<!--suppress ALL -->
<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="70px">
      <el-form-item label="机器人名称">
        <el-input v-model="form.botName" />
      </el-form-item>
      <el-form-item label="企业微信群">
        <el-input v-model="form.botGroup" />
      </el-form-item>
      <el-form-item label="webhook地址">
        <el-input v-model="form.botWebhook" />
      </el-form-item>
      <el-form-item label="备注信息">
        <el-input v-model="form.remark" />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-input  readonly disabled v-model="form.createTime"  />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" v-model="form" @click="editEmail">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //路由跳转携带的参数
      form: {
        botId: '',
        botName: '',
        botGroup: '',
        botWebhook: '',
        remark: ''
      }
    }
  },
  created() {
    this.fetchData()
    this.form.botId = this.$route.query.botId
  },
  mounted() {
  },
  methods: {
    fetchData() {
      // eslint-disable-next-line no-unused-vars
      //推荐使用箭头函数、不用定义this了
      this.axios({
        method: 'GET',
          url: 'http://127.0.0.1:8080/bot/getBotDetial/' + this.$route.query.botId
      }).then(resp=> {
          this.form.botWebhook=resp.data.list[0].botWebhook,
          this.form.botName = resp.data.list[0].botName,
          this.form.botGroup= resp.data.list[0].botGroup,
            this.form.remark= resp.data.list[0].remark,
          this.form.createTime=resp.data.list[0].createTime
      })
    },
    editEmail() {
      console.log(this.form)
      // eslint-disable-next-line no-unused-vars
      var vm = this
      this.axios({
        method: 'POST',
        url: 'http://127.0.0.1:8080/bot/editBot',
        data: vm.form
      }).then(resp=> {
        // eslint-disable-next-line eqeqeq
        if (resp.data == 'success') {
          // 弹框
          this.$message({
            message: '编辑成功',
            type: 'success'
          })
        } else {
          this.$message.error('编辑失败')
        }
        // 添加成功后前往邮箱列表页->index
        this.$router.push({
          name: 'bot',
          path: '/bot'
        })
      })
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

